package com.web4code.codegen.importer;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import com.web4code.codegen.utils.serialize.YamlSerializer;

import org.apache.commons.io.IOUtils;

/**
 * 文件内容导入
 * 
 * @author web4code
 */
public class FileImporter {
    /**
     * 导入文件内容，并转换为配置对象
     * @param fileName
     * @return
     * @throws IOException
     */
    public static <T> T importFile(final String fileName, Class<T> clazz) throws IOException {
        System.out.println("fileName=" + fileName);
        InputStream is = new FileInputStream(fileName);
        final String fileContent = IOUtils.toString(is, "utf-8");
        System.out.println(fileContent);
        T genTable = YamlSerializer.toObject(fileContent, clazz);
        //
        return genTable;
    }
}
